package com.qh.resourcehub.info.ipresource.controller;


import com.qh.resourcehub.info.entity.ApplicationData;
import com.qh.resourcehub.info.ipresource.service.IpApplicationService;
import com.qh.resourcehub.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * IP 申请用户资源管理
 */
@RestController
@RequestMapping("/IpApplication")
public class IpApplicationController {

    @Autowired
    IpApplicationService ipApplicationServicel;

    /**
     * 用户信息高级查询当前填写的以及申请的信息  主任审核 审批内容 APPROVE THE CONTENT
     */
    @PostMapping("/queryIpDataService")
    public ApiResponse queryIpDataService(@RequestBody ApplicationData applicationData) {
        try {
            List<Map<String,Object>> i = ipApplicationServicel.queryIpDataService(applicationData);
            if (i.size()>0){
               return ApiResponse.succeed(i);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }




    /**
     * IP申请新增
     * @param applicationData
     * @return
     */
    @PostMapping("/ApplicationSave")
    public ApiResponse ApplicationSave(@RequestBody ApplicationData applicationData) {
        System.out.println(applicationData);
        try {
            int i = ipApplicationServicel.ApplicationSave(applicationData);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
    /**
     * IP申请修改
     * @param applicationData
     * @return
     */
    @PostMapping("/ApplicationUpdataById")
    public ApiResponse ApplicationUpdataById(@RequestBody ApplicationData applicationData) {
        System.out.println(applicationData);
        try {
            int i = ipApplicationServicel.ApplicationUpdataById(applicationData);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
    /**
     * IP申请删除
     * @param applicationData
     * @return
     */
    @PostMapping("/ApplicationDelById")
    public ApiResponse ApplicationDelById(@RequestBody ApplicationData applicationData) {
        System.out.println(applicationData);
        try {
            int i = ipApplicationServicel.ApplicationDelById(applicationData);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
    /**
     * IP申请提交
     * @param applicationData
     * @return
     */
    @PostMapping("/IPApplicationSubmit")
    public ApiResponse IPApplicationSubmit(@RequestBody ApplicationData applicationData) {
        try {
            int i = ipApplicationServicel.IPApplicationSubmit(applicationData);
            if (i>0){
               return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }

    /**
     * IP申请撤回
     * @param applicationData
     * @return
     */
    @PostMapping("/IPApplicationWithdraw")
    public ApiResponse IPApplicationWithdraw(@RequestBody ApplicationData applicationData) {
        try {
            int i = ipApplicationServicel.IPApplicationWithdraw(applicationData);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
}
